home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / os2 / mus2v131.zip / ModExit.cmd < prev    next >
OS/2 REXX Batch file  |  1996-02-08  |  3KB  |  103 lines

  1. /* ########################################################################
  2.  
  3.    This REXX script will communicate with a running Module Player that
  4.    support a Command Pipe.
  5.  
  6.    The Following commands are used
  7.       Exit -- Terminate the player
  8.  
  9.    ########################################################################
  10. */
  11. '@echo off'                       /* Don't echo commands */
  12. say " Module Player Exit Command V1.0                                          Ethos"
  13.    call OpenPlayer
  14.    if Result <> 0 then do
  15.       say "Error" Error
  16.       return
  17.    end
  18.  
  19.    if CallPlayer("Exit","","") <> 0 then do
  20.       say "Error" Error
  21.       return
  22.    end
  23.    say "Exited"
  24. return
  25.  
  26. /* ########################################################################
  27.  
  28.    Function - CallPlayer
  29.    Eg - if (CallPlayer("Query","Song","") <> 0) then Error
  30.  
  31.    Description - This procedure sends a command message to the player.
  32.                  An error is returned if the player doesn't understand
  33.                  the message or something else is wrong.
  34.                    Result - A stem containing each line of the result
  35.                    Error - Global error code
  36.  
  37.    ########################################################################
  38. */
  39. CallPlayer: procedure expose Result. Player Error
  40.    parse arg Command, SCommand, Arg
  41.  
  42.    Error = ""
  43.    Result.0 = 0
  44.  
  45.    /* Player not loaded */
  46.    if (Player = "") then do
  47.       Error = "Player not Inited"
  48.       return 1
  49.    end
  50.  
  51.    call lineout Player,Command SCommand Arg
  52.  
  53.    /* Get all the results */
  54.    do while (1)
  55.       Line = linein(Player)
  56.  
  57.       /* Error or something */
  58.       if (pos("!!",Line) = 1) then do
  59.          if (Line = "!! OK") then
  60.             return 0
  61.          Error = substr(Line,4)
  62.          return 1
  63.       end;
  64.  
  65.       Result.0 = Result.0 + 1
  66.       I = Result.0
  67.       Result.I = Line
  68.    end
  69.  
  70. return 0
  71.  
  72. /* ########################################################################
  73.  
  74.    Function - OpenPlayer
  75.    Eg - call OpenPlayer
  76.  
  77.    Description - This procedure opens the pipe and sets the following:
  78.                    Player - The name of the pipe - \pipe\Player
  79.                    Version - The pipe comminication version
  80.                    Type - The program running on the other end, 'Text UI'
  81.                    Error - Global Error Code
  82.  
  83.    ########################################################################
  84. */
  85. OpenPlayer:procedure expose Player Version Type Error
  86.    Error = ""
  87.  
  88.    Result = Stream("\pipe\ModulePlayer","C","OPEN");
  89.    if (Result <> "READY:") then do
  90.       Error = "Unable to communicate with the  Player, is it running?"
  91.       Player = ""
  92.       return 1
  93.    end
  94.    Player = "\pipe\ModulePlayer"
  95.  
  96.    /* Get the version */
  97.    S = linein(Player)
  98.    parse var S 'V' Version .
  99.    Type = linein(Player)
  100. return 0
  101.  
  102.  
  103.